import React from 'react';
import { Form, Input } from 'antd';
const FormItem = Form.Item;


class ServiceForm extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            form: this.props.info
        }
    }
    /** 
     * 变更
    */
    upodateValue(value, name) {
        let formValue = {
            ...this.state.form,
            [name]: value
        }
        this.setState({
            form: formValue
        });
        this.props.changeValue(this.state.form);
    }

    render() {
        const { getFieldDecorator } = this.props.form;
        return (
            <Form className="login-form">
                <FormItem>
                {getFieldDecorator('fName', {
                    rules: [{ required: true, message: '请输入...' }],
                    initialValue: this.state.form.fName
                })(
                    <Input placeholder="Username" onChange={(e) => this.upodateValue(e.target.value, 'fName')}/>
                )}
                </FormItem>
                <FormItem>
                {getFieldDecorator('fPrice', {
                    rules: [{ required: true, message: '请输入...' }],
                    initialValue: this.state.form.fPrice
                })(
                    <Input  placeholder="Password" onChange={(e) => this.upodateValue(e.target.value, 'fPrice')}/>
                )}
                </FormItem>
                <FormItem>
                {getFieldDecorator('fDesc', {
                    rules: [{ required: true, message: '请输入...' }],
                    initialValue: this.state.form.fDesc
                })(
                    <Input  placeholder="Password" onChange={(e) => this.upodateValue(e.target.value, 'fDesc')}/>
                )}
                </FormItem>
            </Form>
        )
    }
}

const Service = Form.create()(ServiceForm);

export default Service;